package org.yray.sip.time;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.yray.sip.factory.SipServerFactory;
import org.yray.sip.utils.IcspBeanHolder;

import java.net.InetSocketAddress;

@Data
@Slf4j
public class SendMediaSendTask extends BaseSendTask {

    private byte[] bs;
    private InetSocketAddress sender;
    private int sn;
    private int sentenceSn;
    private String callId;

    public SendMediaSendTask(long time, byte[] bs, InetSocketAddress sender, int sn,int sentenceSn,String callId)
    {
        this.time=time;
        this.bs=bs;
        this.sender=sender;
        this.sn=sn;
        this.sentenceSn=sentenceSn;
        this.callId=callId;

    }
    @Override
    public void doJob() {
        String key=callId+sentenceSn;
        if(sn==0)
        {
            log.info("begin speak time={},sentenceSn={},callId={}",time,sentenceSn,callId);
        }
        if(StopSendRtpTimer.ifClean(key)==null) {
            IcspBeanHolder.getBean(SipServerFactory.class)
                    .getSipServerContext(callId)
                    .getUrtpServerHandler().send(bs, sender);
            //log.info("time="+System.currentTimeMillis());
        }
    }
}
